﻿using System;
using System.Windows.Forms;
using cashbook_psql_cs.BLL;

namespace cashbook_psql_cs
{
    public partial class FrmLogin : Form
    {
      
    
        public FrmLogin()
        {
            InitializeComponent();
        }
        readonly LoginUser user = new LoginUser();
        readonly LoginUserBLL userBll = new LoginUserBLL();

        private void Form1_Load(object sender, EventArgs e)
        {
            //手动计算屏幕分辨率居中
            Screen screen = Screen.PrimaryScreen;
            this.Left = (screen.WorkingArea.Width - this.Width) / 2;
            this.Top = (screen.WorkingArea.Height - this.Height) / 2;
        }

        private void Button1_Click(object sender, EventArgs e)
        {

             user.UserId = TextBox1.Text.Trim();
             user.Password = TextBox2.Text.Trim();

            if (user.UserId == "")
            {
                MessageBox.Show("请输入用户名!");
                return;
            }
            if (user.Password == "")
            {
                MessageBox.Show("请输入密码!");
                return;
            }
            int count = userBll.Login(user);
            if (count > 0)
            {
                MessageBox.Show("登录成功");
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("用户名密码错误");
                TextBox1.Text = "";
                TextBox2.Text = "";
                TextBox1.Focus();
            }
        }
    }
}
